package waitDemo;

public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Object lock1 = new Object();
        Object lock2 = new Object();
        Object lock3 = new Object();
        Thread t1 = new Thread(()->{
            synchronized (lock1) {
                try {
                    lock1.wait();
                    System.out.println("A");
                    synchronized (lock2) {
                        lock2.notify();
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

        });
        Thread t2 = new Thread(()->{
            synchronized (lock2) {
                try {
                    lock2.wait();
                    System.out.println("B");
                    synchronized (lock3) {
                        lock3.notify();
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        });
        Thread t3 = new Thread(()->{
            synchronized (lock3) {
                try {
                    lock3.wait();
                    System.out.println("C");
                    synchronized (lock1) {
                        lock1.notify();
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        });
        t1.start();
        t2.start();
        t3.start();

        Thread.sleep(1000);
        synchronized (lock1) {
            lock1.notify();
        }
    }
}
